package 单例模式;/*
 *author Administrator
 *date 2021年6月2日
 */


import java.sql.SQLOutput;

public class SingDemo {
    public static Student studentLazy = null;
    public static Student studentEager = new Student();
    // 饥汉模式
    private static class SingEager {
        private static  Student student = studentEager;
    }

    private static class SingLazy {
        private static Student student = studentLazy;
    }

    // 懒汉模式
    public static Student getSingInstantByLazy() {
        if (null == SingLazy.student) {
            return SingLazy.student = new Student();
        }else{
            return SingLazy.student;
        }
    }
    // 饥汉模式
    public static Student getSingInstantByEager() {
        return SingEager.student;
    }



    public static void main(String[] args) {
        // 懒汉
        Student s1 = SingDemo.getSingInstantByLazy();
        Student s2 = SingDemo.getSingInstantByLazy();
        // 饥汉
        Student s3 = SingDemo.getSingInstantByEager();
        Student s4 = SingDemo.getSingInstantByEager();



        Student s5 = new Student();
        Student s6 = new Student();

        System.out.println(s1 == s2);
        System.out.println(s3 == s4);
        System.out.println(s5 == s6);
    }

}
class Student{
    private String name;
    private Integer age;
}